using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.Testability;

namespace FireStarterModeller.Test
{
    // Provides a part of the TestUtilsBase class that creates sample DMInheritanceRelationship objects.
    // If these methods create invalid data, then implement custom overrides in the
    // TestUtils class.

    public class TestUtilsDMAssembly
    {
        private static readonly BOTestFactory<DMAssembly> _factory = GetTestFactory();
        public static BOTestFactory<DMAssembly> GetTestFactory()
        {
            return BOTestFactoryRegistry.Instance.Resolve<DMAssembly>();
        }
        /// <summary>
        /// Creates a new saved DMAssembly with a random value assigned to every property
        /// </summary>
        public static DMAssembly CreateSavedDMAssembly()
        {
            DMAssembly dMAssembly = CreateUnsavedValidDMAssembly();
            dMAssembly.Save();
            return dMAssembly;
        }

        /// <summary>
        /// Creates a new unsaved DMAssembly with a random value assigned to every property
        /// </summary>
        public static DMAssembly CreateUnsavedValidDMAssembly()
        {
            DMAssembly dMAssembly = new DMAssembly
                                        {
                                            Name = TestUtilsShared.GetRandomString(20,21),
                                            Solution = TestUtilsShared.CreateSavedDMSolution()
                                        };
            return dMAssembly;
        }

        /// <summary>
        /// Creates a new unsaved DMAssembly where all properties are null, except ID properties
        /// and those with default values.  If there are compulsory properties without
        /// defaults, saving the object will throw an exception.
        /// </summary>
        public static DMAssembly CreateUnsavedDefaultDMAssembly()
        {
            DMAssembly dMAssembly = new DMAssembly();
            return dMAssembly;
        }
    }
// ReSharper disable UnusedMember.Global
    public class BOTestFactoryAssembly : BOTestFactory<DMAssembly>

    {
        public BOTestFactoryAssembly(DMAssembly solution)
            : base(solution)
        {
        }

        public BOTestFactoryAssembly()
        {
        }

        public override void UpdateCompulsoryProperties(IBusinessObject businessObject)
        {
            DMAssembly assembly = (DMAssembly)businessObject;

            BOTestFactory<DMSolution> solutionTestFactory = BOTestFactoryRegistry.Instance.Resolve<DMSolution>();
            solutionTestFactory.SetValueFor(solution => solution.DefaultAssembly, assembly);
            assembly.Solution = solutionTestFactory.CreateValidBusinessObject();
            base.UpdateCompulsoryProperties(businessObject);
        }
    }
    // ReSharper restore UnusedMember.Global
}